﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace _97_自定义ToReadOnlyDictionary方法
{
    class Program
    {
        static void Main(string[] args)
        {
            IReadOnlyDictionary<string, string> 逐浪输出 = GetReadOnly();

            foreach (string item in 逐浪输出.Keys)
            {
                Console.WriteLine("{0}-{1}", item, 逐浪输出[item]);
            }

        }


        static IReadOnlyDictionary<string, string> GetReadOnly()
        {
            IDictionary<string, string> zoomla = new Dictionary<string, string>();
            zoomla["city"] = "Guang Zhou";
            zoomla["name"] = "汪洋";
            zoomla["subject"] = "高端.net程序研发者";
            return zoomla.ToReadOnlyDictionary();
        }
    }

    //定义一个DictionaryExtensions类
    public static class DictionaryExtentsions
    {
        public static IReadOnlyDictionary<Tkey,TValue> ToReadOnlyDictionary<Tkey,TValue>(this IDictionary<Tkey, TValue> srcDictionary)
        {
            return new ReadOnlyDictionary<Tkey, TValue>(srcDictionary);
        }
    }
}
